﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DingHeng.TransportationManagement.Entity;

namespace DingHeng.TransportationManagement.DataAccess
{
    public class AuthorityDataAccess : DAOBase<Authority>
    {
        //public override IQueryable<AuthorityDataAccess> LoadByCondition<T>(System.Linq.Expressions.Expression<Func<AuthorityDataAccess, bool>> condition, params string[] tableName)
        //{
        //    return base.LoadByCondition<AuthorityDataAccess>(condition, tableName);
        //}

        public int Save(Authority entity)
        {
            using (this.context = new TransportationManagementContext())
            {
                var oldEntity = this.context.Authorities.Where(a => a.ID == entity.ID).FirstOrDefault();
                if (oldEntity != null)
                {
                    this.Update(oldEntity, entity);
                }
                else
                {
                    this.Insert(entity);
                }
                return this.SaveChanges();
            }
            
        }

        public override Authority Load(System.Linq.Expressions.Expression<Func<Authority, bool>> condition, params string[] tableName)
        {
            return base.Load(condition, tableName);
        }
        public override IQueryable<Authority> LoadByCondition(System.Linq.Expressions.Expression<Func<Authority, bool>> condition, params string[] tableName)
        {
            return base.LoadByCondition(condition, tableName);
        }
    }
}
